/**
 * 
 */
package com.agrec.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author allomeen
 *
 */
@SuppressWarnings("deprecation")
public class BlindedPopup extends PopupPanel implements ClickListener {

	PopupPanel popup;
	PopupPanel glass;
	String title;
	Widget widget;
	
	public BlindedPopup(String title, Widget widget) {
		this.title = title;
		this.widget = widget;
		blind();
	}

	/**
	 * @param autoHide
	 */
	public BlindedPopup(boolean autoHide, String title, Widget widget) {
		super(autoHide);
		this.title = title;
		this.widget = widget;
		blind();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param autoHide
	 * @param modal
	 */
	public BlindedPopup(boolean autoHide, boolean modal, String title, Widget widget) {
		super(autoHide, modal);
		this.title = title;
		this.widget = widget;
		blind();
		// TODO Auto-generated constructor stub
	}
	
	private void blind() {
		/*
		* Create the glass panel and set a style name for it
		*/
		glass = new PopupPanel();
		glass.setStyleName("rx-glass");
		/*
		* Set the width and the height
		*/
		DOM.setStyleAttribute(glass.getElement(), "width", "100%");
		DOM.setStyleAttribute(glass.getElement(), "height", "100%");
		/*
		* Create a message pop-up and give it a style
		*/
		popup = new PopupPanel(false);
		popup.setStyleName("rx-popup");
		
		/*
		* Create the header label for the message pop-up and give it a
		* style
		*/
		Label header = new Label(title);
		header.setStyleName("rx-popup-header");
		
		/*
		* Create a button for the user to close the pop-up window
		*/
		Button closeButton = new Button("Close", this);
		/*
		* Create a VerticalPanel to hold the various parts of the message
		* box we are going to pop up and add it to the pop-up
		*/
		VerticalPanel popupContents = new VerticalPanel();
		popup.add(popupContents);
		/*
		* At all the various bits to the panel which will hold the contents
		* of the message box
		*/
		popupContents.add(header);
		popupContents.add(widget);
		popupContents.add(closeButton);
		/*
		* Is set the horizontal alignment of the cell that holds the close
		* button so that it is centred
		*/
		popupContents.setCellHorizontalAlignment(closeButton, HasAlignment.ALIGN_CENTER);
		/*
		* Show the glass panel
		*/
		glass.show();
		/*
		* Show the pop-up message box
		*/
		popup.center();
	}
		/*
		* This method is run on the close button is clicked, and its purpose is
		* to clean up the screen
		*/
	public void onClick(Widget sender) {
		/*
		* Hide the pop-up and the glass blinder panel
		*/
		popup.hide();
		glass.hide();
	}
	
	public void hide() {
		// TODO Auto-generated method stub
		super.hide();
		popup.hide();
		glass.hide();
	}

}
